from rest_framework import serializers
from drfstudy.models import Student

class StudentSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True,label='ID')
    name = serializers.CharField(required=False,max_length=20,label='姓名')
    # required = False 允许为空
    age = serializers.IntegerField(required=False,label="年龄")
    sex = serializers.IntegerField(required=False,label="性别")
    create_time = serializers.DateTimeField(required=False,label="创建时间")
    update_time = serializers.DateTimeField(required=False,label="修改时间")
    is_delete = serializers.BooleanField(required=False,label="逻辑删除",default=False)


    def create(self, validated_data):

        return Student.objects.create(**validated_data)